package com.woorigil.social.controller.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.woorigil.social.controller.BaseController;
import com.woorigil.social.domain.flower.Category;
import com.woorigil.social.domain.flower.FlowerCondition;
import com.woorigil.social.domain.flower.FlowerService;
import com.woorigil.social.domain.flower.FlowerTagRef;
import com.woorigil.social.domain.flower.FlowerView;
import com.woorigil.social.domain.flower.Tag;

@Controller
public class FlowerApiController extends BaseController {
	@Autowired FlowerService flowerService;

	@RequestMapping("/api/koreaflower/all")
	public ModelAndView all(FlowerCondition condition, HttpServletRequest request) {
		List<FlowerView> flowerViews = flowerService.findAllFlower();
		List<Category> categories = flowerService.findAllCategory();
		List<Tag> tags = flowerService.findAllTag();
		List<FlowerTagRef> flowerTagRefs = flowerService.findAllFlowerTagRef();
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("flowerViews", flowerViews);
		mav.addObject("categories", categories);
		mav.addObject("tags", tags);
		mav.addObject("flowerTagRefs", flowerTagRefs);
		return mav;
	}
	
	@RequestMapping("/api/koreaflower/flower")
	public ModelAndView flower(FlowerCondition condition, HttpServletRequest request) {
		List<FlowerView> flowerViews = flowerService.findAllFlower();
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("flowerViews", flowerViews);
		return mav;
	}
	
	@RequestMapping("/api/koreaflower/category")
	public ModelAndView category() {
		List<Category> categories = flowerService.findAllCategory();
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("categories", categories);
		return mav;
	}
	
	@RequestMapping("/api/koreaflower/tag")
	public ModelAndView tag() {
		List<Tag> tags = flowerService.findAllTag();
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("tags", tags);
		return mav;
	}
	
	@RequestMapping("/api/koreaflower/byFlowerId")
	public ModelAndView flowerTagRefsByFlowerId(int flowerId) {
		List<FlowerTagRef> flowerTagRefsByFlowerId = flowerService.findFlowerTagRefByFlowerId(flowerId);
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("flowerTagRefsByFlowerId", flowerTagRefsByFlowerId);
		return mav;
	}
	
	@RequestMapping("/api/koreaflower/byTagId")
	public ModelAndView flowerTagRefsByTagId(int tagId) {
		List<FlowerTagRef> flowerTagRefsByTagId = flowerService.findFlowerTagRefByTagId(tagId);
		
		ModelAndView mav = new ModelAndView("");
		mav.addObject("status", "SUCCESS");
		mav.addObject("message", "");
		mav.addObject("flowerTagRefsByTagId", flowerTagRefsByTagId);
		return mav;
	}
}
